package com.yanqu.road.server.cmd.union.cross.trade;

import com.yanqu.road.pb.union.UnionTradeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.union.cross.CrossUnionTradeModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

@Cmd(code = Protocol.S_UNION_TRADE_ROUTE_PATRONS_SELECT_LIST, desc = "已派遣门客信息")
public class PatronsSelectedListCmd extends AbstractCommand {

    private int routeId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionTradeProto.PatronsSelectedListReqMsg  reqMsg = UnionTradeProto.PatronsSelectedListReqMsg.parseFrom(packet.getBytes());
        routeId = reqMsg.getRouteId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData(GamePlayer player) {

        UnionTradeProto.PatronsSelectListRespMsg.Builder respMsg =  UnionTradeProto.PatronsSelectListRespMsg.newBuilder();

        String unionUid = player.getUserInfo().getUnionUid();
        if(!StringUtils.isNullOrEmpty(unionUid)) {
            List<Integer> sendIds =  player.getModule(CrossUnionTradeModule.class).getSendPatronsIdList();
            for(Integer patronsId : sendIds){
                respMsg.addSendedPatronsIds(patronsId);
            }
        }else{
            ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
        }
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_UNION_TRADE_ROUTE_PATRONS_SELECT_LIST, respMsg);
    }
}
